home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / tar-1_11.lha / tar-1.11.2 / tar.h < prev    next >
C/C++ Source or Header  |  1993-03-16  |  9KB  |  294 lines

  1. /* Declarations for tar archives.
  2.    Copyright (C) 1988, 1992, 1993 Free Software Foundation
  3.  
  4. This file is part of GNU Tar.
  5.  
  6. GNU Tar is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Tar is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Tar; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "testpad.h"
  21.  
  22. /* major() and minor() macros (among other things) defined here for hpux */
  23. #ifdef hpux
  24. #include <sys/mknod.h>
  25. #endif
  26.  
  27. /*
  28.  * Kludge for handling systems that can't cope with multiple
  29.  * external definitions of a variable.  In ONE routine (tar.c),
  30.  * we #define TAR_EXTERN to null; here, we set it to "extern" if
  31.  * it is not already set.
  32.  */
  33. #ifndef TAR_EXTERN
  34. #define TAR_EXTERN extern
  35. #endif
  36.  
  37. /*
  38.  * Header block on tape.
  39.  *
  40.  * I'm going to use traditional DP naming conventions here.
  41.  * A "block" is a big chunk of stuff that we do I/O on.
  42.  * A "record" is a piece of info that we care about.
  43.  * Typically many "record"s fit into a "block".
  44.  */
  45. #define    RECORDSIZE    512
  46. #define    NAMSIZ        100
  47. #define    TUNMLEN        32
  48. #define    TGNMLEN        32
  49. #define SPARSE_EXT_HDR  21
  50. #define SPARSE_IN_HDR    4
  51.  
  52. struct sparse
  53.   {
  54.     char offset[12];
  55.     char numbytes[12];
  56.   };
  57.  
  58. struct sp_array
  59.   {
  60.     int offset;
  61.     int numbytes;
  62.   };
  63.  
  64. union record
  65.   {
  66.     char charptr[RECORDSIZE];
  67.     struct header
  68.       {
  69.     char arch_name[NAMSIZ];
  70.     char mode[8];
  71.     char uid[8];
  72.     char gid[8];
  73.     char size[12];
  74.     char mtime[12];
  75.     char chksum[8];
  76.     char linkflag;
  77.     char arch_linkname[NAMSIZ];
  78.     char magic[8];
  79.     char uname[TUNMLEN];
  80.     char gname[TGNMLEN];
  81.     char devmajor[8];
  82.     char devminor[8];
  83.     /* these following fields were added by JF for gnu */
  84.     /* and are NOT standard */
  85.     char atime[12];
  86.     char ctime[12];
  87.     char offset[12];
  88.     char longnames[4];
  89. #ifdef NEEDPAD
  90.     char pad;
  91. #endif
  92.     struct sparse sp[SPARSE_IN_HDR];
  93.     char isextended;
  94.     char realsize[12];    /* true size of the sparse file */
  95.     /* char    ending_blanks[12];*//* number of nulls at the
  96.        end of the file, if any */
  97.       }
  98.     header;
  99.     struct extended_header
  100.       {
  101.     struct sparse sp[21];
  102.     char isextended;
  103.       }
  104.     ext_hdr;
  105.   };
  106.  
  107. /* The checksum field is filled with this while the checksum is computed. */
  108. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  109.  
  110. /* The magic field is filled with this if uname and gname are valid. */
  111. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  112.  
  113. /* The linkflag defines the type of file */
  114. #define    LF_OLDNORMAL    '\0'    /* Normal disk file, Unix compat */
  115. #define    LF_NORMAL    '0'    /* Normal disk file */
  116. #define    LF_LINK        '1'    /* Link to previously dumped file */
  117. #define    LF_SYMLINK    '2'    /* Symbolic link */
  118. #define    LF_CHR        '3'    /* Character special file */
  119. #define    LF_BLK        '4'    /* Block special file */
  120. #define    LF_DIR        '5'    /* Directory */
  121. #define    LF_FIFO        '6'    /* FIFO special file */
  122. #define    LF_CONTIG    '7'    /* Contiguous file */
  123. /* Further link types may be defined later. */
  124.  
  125. /* Note that the standards committee allows only capital A through
  126.    capital Z for user-defined expansion.  This means that defining something
  127.    as, say '8' is a *bad* idea. */
  128. #define LF_DUMPDIR    'D'    /* This is a dir entry that contains
  129.                        the names of files that were in
  130.                        the dir at the time the dump
  131.                        was made */
  132. #define LF_LONGLINK    'K'    /* Identifies the NEXT file on the tape
  133.                        as having a long linkname */
  134. #define LF_LONGNAME    'L'    /* Identifies the NEXT file on the tape
  135.                        as having a long name. */
  136. #define LF_MULTIVOL    'M'    /* This is the continuation
  137.                        of a file that began on another
  138.                        volume */
  139. #define LF_NAMES    'N'    /* For storing filenames that didn't
  140.                        fit in 100 characters */
  141. #define LF_SPARSE    'S'    /* This is for sparse files */
  142. #define LF_VOLHDR    'V'    /* This file is a tape/volume header */
  143. /* Ignore it on extraction */
  144.  
  145. /*
  146.  * Exit codes from the "tar" program
  147.  */
  148. #define    EX_SUCCESS    0    /* success! */
  149. #define    EX_ARGSBAD    1    /* invalid args */
  150. #define    EX_BADFILE    2    /* invalid filename */
  151. #define    EX_BADARCH    3    /* bad archive */
  152. #define    EX_SYSTEM    4    /* system gave unexpected error */
  153. #define EX_BADVOL    5    /* Special error code means
  154.                    Tape volume doesn't match the one
  155.                    specified on the command line */
  156.  
  157. /*
  158.  * Global variables
  159.  */
  160. TAR_EXTERN union record *ar_block;    /* Start of block of archive */
  161. TAR_EXTERN union record *ar_record;    /* Current record of archive */
  162. TAR_EXTERN union record *ar_last;    /* Last+1 record of archive block */
  163. TAR_EXTERN char ar_reading;    /* 0 writing, !0 reading archive */
  164. TAR_EXTERN int blocking;    /* Size of each block, in records */
  165. TAR_EXTERN int blocksize;    /* Size of each block, in bytes */
  166. TAR_EXTERN char *info_script;    /* Script to run at end of each tape change */
  167. TAR_EXTERN char *name_file;    /* File containing names to work on */
  168. TAR_EXTERN char filename_terminator;    /* \n or \0. */
  169. TAR_EXTERN char *tar;        /* Name of this program */
  170. TAR_EXTERN struct sp_array *sparsearray;    /* Pointer to the start of the scratch space */
  171. TAR_EXTERN int sp_array_size;    /* Initial size of the sparsearray */
  172. TAR_EXTERN int tot_written;    /* Total written to output */
  173. TAR_EXTERN struct re_pattern_buffer
  174.  *label_pattern;        /* compiled regex for extract label */
  175. TAR_EXTERN char **ar_files;    /* list of tape drive names */
  176. TAR_EXTERN int n_ar_files;    /* number of tape drive names */
  177. TAR_EXTERN int cur_ar_file;    /* tape drive currently being used */
  178. TAR_EXTERN int ar_files_len;    /* malloced size of ar_files */
  179. TAR_EXTERN char *current_file_name, *current_link_name;
  180.  
  181. /*
  182.  * Flags from the command line
  183.  */
  184. TAR_EXTERN int cmd_mode;
  185. #define CMD_NONE    0
  186. #define CMD_CAT        1    /* -A */
  187. #define CMD_CREATE    2    /* -c */
  188. #define CMD_DIFF    3    /* -d */
  189. #define CMD_APPEND    4    /* -r */
  190. #define CMD_LIST    5    /* -t */
  191. #define CMD_UPDATE    6    /* -u */
  192. #define CMD_EXTRACT    7    /* -x */
  193. #define CMD_DELETE    8    /* -D */
  194. #define CMD_VERSION    9    /* --version */
  195.  
  196.  
  197. TAR_EXTERN int f_reblock;    /* -B */
  198. #if 0
  199. TAR_EXTERN char f_dironly;    /* -D */
  200. #endif
  201. TAR_EXTERN int f_run_script_at_end;    /* -F */
  202. TAR_EXTERN int f_gnudump;    /* -G */
  203. TAR_EXTERN int f_follow_links;    /* -h */
  204. TAR_EXTERN int f_ignorez;    /* -i */
  205. TAR_EXTERN int f_keep;        /* -k */
  206. TAR_EXTERN int f_startfile;    /* -K */
  207. TAR_EXTERN int f_local_filesys;    /* -l */
  208. TAR_EXTERN int tape_length;    /* -L */
  209. TAR_EXTERN int f_modified;    /* -m */
  210. TAR_EXTERN int f_multivol;    /* -M */
  211. TAR_EXTERN int f_new_files;    /* -N */
  212. TAR_EXTERN int f_oldarch;    /* -o */
  213. TAR_EXTERN int f_exstdout;    /* -O */
  214. TAR_EXTERN int f_use_protection;/* -p */
  215. TAR_EXTERN int f_absolute_paths;/* -P */
  216. TAR_EXTERN int f_sayblock;    /* -R */
  217. TAR_EXTERN int f_sorted_names;    /* -s */
  218. TAR_EXTERN int f_sparse_files;    /* -S  ... JK */
  219. TAR_EXTERN int f_namefile;    /* -T */
  220. TAR_EXTERN int f_verbose;    /* -v */
  221. TAR_EXTERN char *f_volhdr;    /* -V */
  222. TAR_EXTERN int f_confirm;    /* -w */
  223. TAR_EXTERN int f_verify;    /* -W */
  224. TAR_EXTERN int f_exclude;    /* -X */
  225. TAR_EXTERN char *f_compressprog;    /* -z and -Z */
  226. TAR_EXTERN int f_do_chown;    /* --do-chown */
  227. TAR_EXTERN int f_totals;    /* --totals */
  228. TAR_EXTERN int f_remove_files;    /* --remove-files */
  229. TAR_EXTERN int f_ignore_failed_read;    /* --ignore-failed-read */
  230. TAR_EXTERN int f_checkpoint;    /* --checkpoint */
  231. TAR_EXTERN int f_show_omitted_dirs;    /* --show-omitted-dirs */
  232. TAR_EXTERN char *f_volno_file;    /* --volno-file */
  233. TAR_EXTERN int f_force_local;    /* --force-local */
  234. TAR_EXTERN int f_atime_preserve;/* --atime-preserve */
  235. TAR_EXTERN int f_compress_block; /* --compress-block */
  236.  
  237. /*
  238.  * We default to Unix Standard format rather than 4.2BSD tar format.
  239.  * The code can actually produce all three:
  240.  *    f_standard    ANSI standard
  241.  *    f_oldarch    V7
  242.  *    neither        4.2BSD
  243.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  244.  * The only advantage to the "neither" option is that we can cmp our
  245.  * output to the output of 4.2BSD tar, for debugging.
  246.  */
  247. #define        f_standard        (!f_oldarch)
  248.  
  249. /*
  250.  * Structure for keeping track of filenames and lists thereof.
  251.  */
  252. struct name
  253.   {
  254.     struct name *next;
  255.     short length;        /* cached strlen(name) */
  256.     char found;            /* A matching file has been found */
  257.     char firstch;        /* First char is literally matched */
  258.     char regexp;        /* This name is a regexp, not literal */
  259.     char *change_dir;        /* JF set with the -C option */
  260.     char *dir_contents;        /* JF for f_gnudump */
  261.     char fake;            /* dummy entry */
  262.     char name[1];
  263.   };
  264.  
  265. TAR_EXTERN struct name *namelist;    /* Points to first name in list */
  266. TAR_EXTERN struct name *namelast;    /* Points to last name in list */
  267.  
  268. TAR_EXTERN int archive;        /* File descriptor for archive file */
  269. TAR_EXTERN int errors;        /* # of files in error */
  270.  
  271. TAR_EXTERN char *gnu_dumpfile;
  272.  
  273. /*
  274.  * Error recovery stuff
  275.  */
  276. TAR_EXTERN char read_error_flag;
  277.  
  278.  
  279. /*
  280.  * Declarations of functions available to the world.
  281.  */
  282. union record *findrec ();
  283. void userec ();
  284. union record *endofrecs ();
  285. void anno ();
  286.  
  287. #if defined (HAVE_VPRINTF) && __STDC__
  288. void msg (char *,...);
  289. void msg_perror (char *,...);
  290. #else
  291. void msg ();
  292. void msg_perror ();
  293. #endif
  294.